package br.com.clicarros.dao.Implementacao.cliente;

import br.com.clicarros.dao.Implementacao.AbstractDAO;

import br.com.clicarros.dominio.cliente.Cliente;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import br.com.clicarros.util.UtilHibernate;

/**
 *
 * @author Bruno
 */

public class DAOCliente extends AbstractDAO {
    
   
    
    @Override
    public Cliente consultarId(Object o) throws ClassNotFoundException, SQLException, Exception {
         
      Cliente c = (Cliente) o;
                
       Session session = UtilHibernate.openSession();

       c  = (Cliente)  session.load(c.getClass(), c.getIdCliente());  
       
       session.close();

       return c; 
    }


    @Override
     public List<Object> consultar(Object o) throws SQLException, ClassNotFoundException, Exception {
        
        Cliente c = (Cliente) o;
                
       Session session = UtilHibernate.openSession();
       
       StringBuilder sql = new StringBuilder("from Cliente as c where ");
       sql.append(" c.nome like '%");
       sql.append(c.getNome());
       sql.append("%'");
       sql.append("and c.sobrenome like '%");
       sql.append(c.getSobrenome());
       sql.append("%'");
       sql.append("and c.cpf like '%");
       sql.append(c.getCpf());
       sql.append("%'");
       sql.append("and c.telefone like '%");
       sql.append(c.getTelefone());
       sql.append("%'");
       sql.append("and c.email like '%");
       sql.append(c.getEmail());
       sql.append("%'");
       Query q = session.createQuery(sql.toString());
       
       //q.setParameter("modelo", a.getVeiculo().getModelo());


       List<Object> retorno = q.list();
     
       return retorno;
       
       }            
                       
   }

